package com.wc.AlgoOJ.CT0207;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/22 19:52
 * @description blg的课堂作业
 * http://43.138.190.70:8888/p/CT0207
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int n, k;
    static String s1, s2;

    public static void main(String[] args) {
        n = sc.nextInt();
        while (n-- > 0) {
            k = sc.nextInt();
            s1 = sc.next();
            s2 = sc.next();
            int len1 = s1.length();
            int len2 = s2.length();
            if (len1 != len2) {
                out.println("NO");
                continue;
            }
            int[][] a = new int[k][128];
            for (int i = 0; i < k; i++) {
                for (int j = i; j < len1; j += k) {
                    a[i][s1.charAt(j)]++;
                    a[i][s2.charAt(j)]--;
                }
            }
            boolean flg = true;
            for (int i = 0; i < k; i++) {
                for (int j = 'a'; j <= 'z'; j++) {
                    if (a[i][j] != 0) {
                        flg = false;
                        break;
                    }
                }
                if (!flg) {
                    break;
                }
            }
            if (flg) {
                out.println("YES");
            } else {
                out.println("NO");
            }
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}